package com.aphrodite.ui.widgets;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 * A list that allows multiple items to be selected
 * 
 * @author kentelt
 * 
 */
public class MultiSelectList extends OptionButtonGroup {

	public MultiSelectList(Theme theme, int width, int height) {
		super(theme, width, height);
	}

	public void fire() {
		setSelectedIndex(selIndex);
		if (clikListenr != null) {
			clikListenr.clickPerformed(this);
		}
	}

	// radioht=itemheight-4
	/* needs to be overriden. renders the icon and the string item */
	void renderItem(final Graphics g, final boolean isSelected, final int index, final int y) {
		tmpImage = (Image) icons.elementAt(index);
		tmpString = (String) list.elementAt(index);
		WidgetHelper.drawCheck(g, imagePad, y + 2, selectedArray[index]);
		renderCaption(g, isSelected, y);
	}

	final void computeTextStart() {
		textStart = imagePad + WidgetHelper.checkBoxHeight + 2 + getWidestIcon();
	}

	/**
	 * 
	 * @param index
	 * @throws ArrayIndexOutOfBoundsException
	 *             if an invalid <code>index</code> was specified
	 */
	public void setSelectedIndex(int index) {
		selectedArray[index] = !selectedArray[index];
		reDrawWidget();
	}
}
